#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_exam1.py
# author:王雯雯
# datetime:2024-11-12 
# software: PyCharm

import hashlib

def encrypt_password(password):

    hash_object = hashlib.sha256(password.encode())
    return hash_object.hexdigest()

def login():

    stored_students = []
    with open("D:\students.txt", "r") as f:
        for line in f.readlines():
            parts = line.strip().split(" ")
            stored_students.append((parts[0], parts[1], parts[2]))

    name = input("请输入登录同学姓名: ")
    account = ""
    password = ""
    for student in stored_students:

        if student[0] == name:

            account = input("请输入账号: ")

            if student[1] == account:

                password = input("请输入密码（明文）: ")

                encrypted_password = encrypt_password(password)
                if student[2] == encrypted_password:
                    print("您登录成功")
                    return
                else:
                    print("您登录失败，密码错误")
                    return
            else:
                print("您登录失败，账号错误")
                return
    print("您登录失败，姓名不存在")